﻿@model U413.MvcUI.ViewModels.TerminalViewModel
@using U413.Domain.Utilities;
@using System.Configuration;
@{
    ViewBag.Title = Model.Title;
}
<script type="text/javascript">
    var rootPath = '@Url.Content("~")';
    soundManager.url = rootPath + 'Content/SoundManager2/';
    //soundManager.useHTML5Audio = true;
    soundManager.allowScriptAccess = 'always';
    $(function ()
    {
        @if (DateTime.Now.Month == 10)
        {
            <text>
                soundManager.onready(function ()
                {
                    soundManager.createSound({
                        id: 'halloween',
                        url: rootPath + 'Content/sounds/TheDarkeningGround.mp3',
                        autoLoad: true,
                        autoPlay: true,
                        stream: true,
                        volume: 75
                    });
                });
                Setup(rootPath + 'Content/sounds/typewriter.mp3');
                StopButton('halloween');
            </text>
        }
        else if (DateTime.Now.Month == 12)
        {
            <text>
                soundManager.onready(function ()
                {
                    soundManager.createSound({
                        id: 'xmas',
                        url: rootPath + 'Content/sounds/Maenam.mp3',
                        autoLoad: true,
                        autoPlay: true,
                        stream: true,
                        volume: 75
                    });
                });
                Setup(rootPath + 'Content/sounds/techtyping.mp3');
                StopButton('xmas');
                $(document).snowfall({ flakeIndex: 9000, minSize: 1, maxSize: 5, round: true, flakeCount: 100 });
            </text>
        }
        else
        {
            @:Setup(rootPath + 'Content/sounds/techtyping.mp3');
        }
    });

    function StopButton(soundName)
    {
        $('<img src="' + rootPath + 'Content/stop.png" />').css({
            position: 'fixed',
            right: 20,
            top: 20,
            width: '25px',
            cursor: 'pointer',
            zIndex: 9000,
            opacity: '.50'
        }).prependTo('body')
        .click(function (e)
        {
            soundManager.pause(soundName);
            $(this).hide();
            PlayButton(soundName);
        });
    }

    function PlayButton(soundName)
    {
        $('<img src="' + rootPath + 'Content/play.png" />').css({
            position: 'fixed',
            right: 20,
            top: 20,
            width: '25px',
            cursor: 'pointer',
            zIndex: 9000,
            opacity: '.50'
        }).prependTo('body')
        .click(function (e)
        {
            soundManager.resume(soundName);
            $(this).hide();
            StopButton(soundName);
        });
    }

    function Setup(soundFile)
    {
        $(window).resize(function ()
        {
            $('#frame').height($(window).height() - 175);
        }).resize();

        $.coolType.setup(
        {
            soundFile: soundFile,
            playSound: true,
            speed: 25,
            onSoundLoaded: function ()
            {
                $('#commandForm').u413Client(
                {
                    elementToScroll: '#frame > .subFrame',
                    apiUrl: '@ConfigurationManager.AppSettings["ApiUrl"]',
                    sessionId: '@Model.SessionId'
                });
            }
        });
    }
</script>
@if (DateTime.Now.Month == 10)
{
    @:<img class="backgroundImage" src="@Url.Content("~/content/background_halloween.jpg")">
}
else if (DateTime.Now.Month == 12)
{
    @:<img class="backgroundImage" src="@Url.Content("~/content/background_xmas.jpg")">
}
else
{
    @:<img class="backgroundImage" src="@Url.Content("~/content/background.jpg")">
}
<div style="top: 0; left: 0; width: 100%; position: absolute; z-index: 1;">
    <div id="frame">
        <div class="opacityFrame">
        </div>
        <div class="subFrame" style="overflow:auto;">
            @using (Html.BeginForm("Index", "Terminal", FormMethod.Post, new { id = "commandForm" }))
            {
                <div>
                    <div id="terminalDisplay">
                        <noscript>
                            @Html.Raw(Model.Display)
                        </noscript>
                    </div>
                    @Html.HiddenFor(x => x.Display)
                    <div id="notifications">
                        <noscript>
                            @Html.Raw(Model.Notifications)
                        </noscript>
                    </div>
                    @Html.HiddenFor(x => x.Notifications)
                    <div id="loading">
                    </div>
                    <span id="contextDisplay"><span id="context"><noscript>@Model.ContextText</noscript></span>&gt;&nbsp;</span>
                    @if (Model.PasswordField)
                    {
                        @Html.PasswordFor(x => x.Cli, new { autofocus = "autofocus", autocomplete = "off" })
                    }
                    else
                    {
                        @Html.TextBoxFor(x => x.Cli, new { autofocus = "autofocus", autocomplete = "off" })
                    }
                </div>
                <br />
                <br />
            }
        </div>
    </div>
</div>
